<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\admin\model\Block as BlockModel;

/**
 * 首页接口.
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页.
     */
    public function index()
    {

        $BlockModel = new BlockModel();

        //顶部轮播
        $banner = $BlockModel->getList(['type' => 'banner', 'name'=>'indexfocus','status' => 1], 99, 'title,image,news_id,urltype,url');
        $data['banner'] = $banner['data'];
        //金刚位
        $jinggang = $BlockModel->getList(['type' => 'jinggang','name'=>'jinggang', 'status' => 1], 99, 'id,title,image,news_id,urltype,url,start_status');
        $data['block'] = $jinggang['data'];



        //这个会员等级存在的话 显示
        $level_func = [];
        $levelinfo =  (new \app\admin\model\Label())->where('id',$this->auth->level)->find();
        if ($levelinfo && $levelinfo['status']==1){
            $level_func = explode(',',$levelinfo['func']);
        }

//        dump($level_func);die;
        foreach ($data['block'] as &$vv){
            if (!in_array($vv['id'],$level_func)){
                $vv['urltype'] ='miniapp';
                $vv['url'] ='/pages/pageDetail?newsId='.$vv['news_id'];
            }
        }

        //
        $vipintro = $BlockModel->getList(['type' => 'banner','name'=>'vipintro', 'status' => 1], 99, 'title,image,news_id,urltype,url');
        $data['vipintro'] = isset($vipintro['data'][0])?$vipintro['data'][0]:[];

        $this->success('请求成功', $data);
    }

    /**
     * 知情同意内容
     * @return void
     */
    public  function zhiqing(){
        $BlockModel = new BlockModel();

        $zhiqing = $BlockModel->getList(['type' => 'zhiqing','name'=>'zhiqing', 'status' => 1], 1, 'title,image,news_id,urltype,url,news_id');
        $zhiqing = $zhiqing['data'];
        $content ='未设置内容,请管理员及时设置';
        if(!empty($zhiqing)){
            $content =   (new \app\admin\model\News())->where('id',$zhiqing[0]['news_id'])->value('content');
        }
        $this->success('请求成功', ['content'=>$content]);
    }


    /**
     * 知情同意内容
     * @return void
     */
    public  function vipintro(){
        $BlockModel = new BlockModel();

        $zhiqing = $BlockModel->getList(['type' => 'banner', 'name'=>'vipintro','status' => 1], 1, 'title,image,news_id,urltype,url,news_id');
        $zhiqing = $zhiqing['data'];
        $content ='未设置内容,请管理员及时设置';
        if(!empty($zhiqing)){
            $content =   (new \app\admin\model\News())->where('id',$zhiqing[0]['news_id'])->value('content');
        }
        $this->success('请求成功', ['content'=>$content]);
    }

    public function articleinfo()
    {
        $id = $this->request->get('id');
        $content = (new \app\admin\model\News())->where('id', $id)->value('content');

        $this->success('请求成功', ['content' => $content]);
    }


}
